<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="政策:" prop="pId">
        <el-select v-model="queryParams.pId" size="mini" clearable>
          <el-option
            v-for="item in policyList"
            :key="item.id"
            :label="item.title"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="政策" :show-overflow-tooltip="true" prop="title" key="title" align="center"/>
      <el-table-column label="用户昵称" key="nickName" prop="nickName" align="center"/>
      <el-table-column label="收藏时间" prop="createTime" align="center">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {pageList} from "@/api/triones/collect";
import { list } from '@/api/triones/policy'
export default {
  name: "index",
  data() {
    return {
      loading: true,
      showSearch: true,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pId: undefined
      },
      dataList: [],
      total: 0,
      policyList: []
    }
  },
  created() {
    this.getList();
    this.getPolicyList();
  },
  methods: {
    getList() {
      this.loading = true;
      pageList(this.queryParams).then(res => {
        this.dataList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    getPolicyList() {
      list().then(res => {
        this.policyList = res.data;
      })
    }
  }
}
</script>
<style scoped lang="scss">

</style>
